import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from "../views/Home.vue"  //静态导入

//路由懒加载
// const Home = () => import(/* webpackChunkName: "Home" */ '../views/Home.vue')
import { Notification } from 'element-ui'; //在js文件中，需单独引入提示

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home,
  },
  {
    path: '*',
    redirect:"/Home"
  },
  {
    path:"/about",
    name:"about",
    component:()=>import("../views/index/about.vue")
  },
  {
    path:"/order",
    name:"order",
    component:()=>import("../views/index/order.vue")
  },
  {
    path:"/collect",
    name:"collect",
    component:()=>import("../views/index/collect.vue")
  },
  {
    path:"/goods",
    name:"goods",
    component:()=>import("../views/index/goods.vue")
  },
  {
    path:"/goods/details/:productID",
    name:"details",
    component:()=>import("../views/index/det/details.vue")
  },
  // {
  //   path:"/goods/details",
  //   name:"details",
  //   component:()=>import("../views/index/det/details.vue")
  // },
  {
    path:"/shoppingCart",
    name:"shoppingCart",
    component:()=>import("../views/index/shoppingCart.vue")
  },
  {
    path:"/ConfirmOrder",
    name:"ConfirmOrder",
    component:()=>import("../views/index/det/ConfirmOrder.vue")
  },
]
const router = new VueRouter({
  routes
})
//路由守卫-进行全局路由拦截

// let whiteList=["/","/goods","/about"]
// router.beforeEach((to,from,next)=>{
//    console.log("to",to);
//    let user=JSON.parse(localStorage.getItem("user") || {})
//   //  let user=localStorage.getItem("user") 
//    console.log('user',user);
//    if(user.user_id){
//        next()
//    }else{
//     if(whiteList.indexOf(to.path)!=-1){
//       next()
//     }else{
//       Notification.warning({
//         duration:2000,
//         message:"没有请先进行登录"
//     })
//     // .then(()=>{
//     //   let a=this.$store.state.dia
//     //     next(dia=true)
//     // }).catch(()=>{
//     //    console.log("请先登录");
//     // })
//     }
//    }
// })



export default router
